<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客管理-发布新博客</title>
    <link rel="stylesheet" href="../../static/lib/semantic-ui/semantic.min.css">
    <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css">
    <link rel="stylesheet" href="../../static/css/style.css">
</head>
<body>
<!--导航start-->
<nav th:replace="admin/_fragments :: menu(1)" class="ui attached inverted segment padded-tb-mini shadow-small">
    <div class="ui container">
        <div class="ui menu inverted secondary stackable">
            <h2 class="ui header teal item">管理后台</h2>
            <a href="#" class="active item mobile-hide m-item"><i class="small icon home"></i>博客</a>
            <a href="#" class="item mobile-hide m-item"><i class="small icon idea"></i>分类</a>
            <a href="#" class="item mobile-hide m-item"><i class="small icon tags"></i>标签</a>
            <div class="right menu m-item mobile-hide">
                <div class="ui item dropdown">
                    <div class="text">
                        <img src="https://picsum.photos/id/1005/100/100" class="ui avatar image">
                        多俊睿
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item">注销</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui button icon black button-right-top mobile-show menu toggle">
        <i class="icon sidebar"></i>
    </a>
</nav>
<!--导航end-->

<!--二级导航条start-->
<div class="ui menu attached pointing">
    <div class="ui container">
        <div class="right menu">
            <a href="#" class="active item teal">发布新博客</a>
            <a href="#" class="item">博客列表</a>
        </div>
    </div>
</div>
<!--二级导航条end-->

<!--中间内容start-->
<div class="padded-tb-large container">
    <div class="ui container">
        <form method="post" class="ui form" action="#" th:action="@{/admin/blogs}" id="blog-form">
            <input type="hidden" name="published">
            <div class="field required">
                <div class="ui left labeled input">
                    <div class="ui selection teal basic dropdown label compact">
                        <input type="hidden" value="原创">
                        <i class="dropdown icon"></i>
                        <div class="text">原创</div>
                        <div class="menu">
                            <div class="item" data-value="原创">原创</div>
                            <div class="item" data-value="转载">转载</div>
                            <div class="item" data-value="翻译">翻译</div>
                        </div>
                    </div>
                    <input type="text" name="title" placeholder="标题">
                </div>
            </div>

            <div class="required field">
                <div id="md-content" style="z-index: 1 !important;">
                    <textarea placeholder="博客内容..." name="content" style="display: none"></textarea>
                </div>
            </div>

            <div class="two fields">
                <div class="required field">
                    <div class="ui left labeled action input">
                        <label class="ui compact blue basic label">分类</label>
                        <div class="ui fluid selection dropdown">
                            <input type="hidden" name="type.id">
                            <i class="dropdown icon"></i>
                            <div class="default text">分类</div>
                            <div class="menu">
                                <div class="item" data-value="1" th:each="type : ${types}" th:data-value="${type.id}"
                                     th:text="${type.name}">错误日志
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="field">
                    <div class="ui left labeled action input">
                        <label class="ui compact yellow basic label">标签</label>
                        <div class="ui fluid selection dropdown multiple search">
                            <input type="hidden" name="tagIds">
                            <i class="dropdown icon"></i>
                            <div class="default text">标签</div>
                            <div class="menu">
                                <div th:each="tag : ${tags}" class="item" data-value="1" th:data-value="${tag.id}"
                                     th:text="${tag.name}">JavaScript
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="required field">
                <div class="ui left teal labeled input">
                    <label class="ui teal basic label">首图链接</label>
                    <input type="text" name="firstImage" placeholder="首图引用地址...">
                </div>
            </div>

            <div class="inline fields">
                <div class="field">
                    <div class="ui checkbox">
                        <input class="hidden" type="checkbox" name="recommend" id="recommend">
                        <label for="recommend">好文推荐</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input class="hidden" type="checkbox" name="copyright" id="copyright">
                        <label for="copyright">版权声明</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input class="hidden" type="checkbox" name="appreciation" id="appreciation">
                        <label for="appreciation">支持赞赏</label>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input class="hidden" type="checkbox" name="comment" id="comment" checked>
                        <label for="comment">开启评论</label>
                    </div>
                </div>
            </div>
            <!--表单验证错误提示div-->
            <div class="ui error message"></div>

            <div class="ui container right aligned">
                <button type="button" class="ui button" onclick="window.history.go(-1)">返回</button>
                <button class="ui orange button" type="button" id="save-btn">保存</button>
                <button class="ui green button" type="button" id="publish-btn">发布</button>
            </div>

        </form>
    </div>
</div>
<!--中间内容end-->
<br>
<br>
<br>
<!--底部start-->
<footer th:replace="admin/_fragments :: footer" class="ui segment inverted vertical padded-tb-massive">
    <div class="ui container center aligned">
        <div class="ui grid inverted divided stackable">
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../../static/images/github.png" class="ui image rounded" alt="Github二维码"
                             style="width: 110px">
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header text-lined text-spaced text-thin">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事（User Story）</a>
                    <a href="#" class="item">关于刻意练习的清单</a>
                    <a href="#" class="item">失败要趁早</a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header text-lined text-spaced text-thin">联系我</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">Email：duojunrui@163.com</a>
                    <a href="#" class="item">QQ: 1358528202</a>
                    <a href="#" class="item">WeChat: djr1119</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header text-lined text-spaced text-thin">Blog</h4>
                <p class="text-lined text-spaced text-thin opacity-mini">
                    这是我的个人博客，会分享关于编程、写作、思考相关的任何内容，希望可以给来到这儿的人有所帮助...</p>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="text-lined text-spaced text-thin opacity-tiny">Copyright © 2019-2020 Duojunrui Designed by
            Duojunrui</p>
    </div>
</footer>
<!--底部end-->

<th:block th:replace="admin/_fragments :: script">
    <script src="../../static/lib/jquery/jquery-3.4.1.min.js"></script>
    <script src="../../static/lib/semantic-ui/semantic.min.js"></script>
    <script src="../../static/lib/editormd/editormd.min.js"></script>
</th:block>

<script>

    /*-----初始化Markdown编辑器-----*/
    var contentEditor;
    $(function () {
        contentEditor = editormd("md-content", {
            width: "100%",
            height: 640,
            syncScrolling: "single",
            // path: "../static/lib/editormd/lib/"
            path: "/lib/editormd/lib/"
        });
    });

    /*---手机导航栏隐藏和展开----*/
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('mobile-hide');
    });

    $('.ui.dropdown').dropdown();

    $('#save-btn').click(function () {
        $('[name="published"]').val(false);
        $('#blog-form').submit();
    });

    $('#publish-btn').click(function () {
        $('[name="published"]').val(true);
        $('#blog-form').submit();
    });

    /*表单验证*/
    $(".ui.form").form({
        fields: {
            title: {
                identifier: "title",
                rules: [{
                    type: "empty",
                    prompt: "请输入博客标题！"
                }]
            },
            content: {
                identifier: "content",
                rules: [{
                    type: "empty",
                    prompt: "请输入博客内容！"
                }]
            },
            typeId: {
                identifier: "typeId",
                rules: [{
                    type: "empty",
                    prompt: "请选择博客分类！"
                }]
            },
            firstImage: {
                identifier: "firstImage",
                rules: [{
                    type: "empty",
                    prompt: "请输入博客首图地址！"
                }]
            }
        }
    });


</script>
</body>
</html>